<%@ include file="./jsp/common.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    
    <title>SSI</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
	<script type="text/javascript" src="./js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="./js/common.js"></script>
	<script type="text/javascript">
	function search(obj){
	var searchval=document.getElementById("search");
	var serchid;
	if(obj.name=="goods"){
		serchid=1;
	}else if(obj.name=="shop"){
		serchid=2;
	}else{
		serchid=3;
		}
	//alert("searchval="+serchval.value+",searchid="+serchid);
	$.ajax({
		   type: "POST",
		   url: path+"index/index_searchGoodsAndShop.do",
		   data: {"searchval":searchval.value,"searchid":serchid},
		   success: function(root){
			   var root=eval('('+root+')');
			     var goodsList=root.goodsList;
			     var shopList=root.shopList;
				var goods="";
				if(undefined!=goodsList){
				for ( var i = 0; i < goodsList.length; i++) {
					goods+="<tr>"
					+"<td><a href='"+goodsList[i].nameUrl+"' target=\"_blank\"><img src=\""+goodsList[i].imgUrl+"\" style=\"width: 200px;height: 100px\"></a></td>"
	        		+"<td ><a href=\""+goodsList[i].nameUrl+"\"  target=\"_blank\">"+goodsList[i].name+"</a></td>"
	        		+"<td>"+goodsList[i].createAuthor+"</td>"
	        		+"<td>"+goodsList[i].createDate+"</td>"
	        		+"<td>"+goodsList[i].goodsType+"</td>" 
	        		+"<td>"+goodsList[i].other+"</td>"
					+"</tr>";
					
				}

				}else{
					goods+="<tr><td colspan=\"6\">没有找到相关商品</td></tr>";

					}
				
				var shops="";
				if(undefined!=shopList){
					for ( var i = 0; i < shopList.length; i++) {
						shops+="<tr>"
					   +"<td>"+shopList[i].id+"</td>"
		        		+"<td ><a href=\"shop/shop_shopIndex.do?shop.id="+shopList[i].id+"\"  target=\"_blank\">"+shopList[i].shopName+"</a></td>"
		        		+"<td>"+shopList[i].shopkeeper+"</td>" 
		        		+"<td>"+shopList[i].createDate+"</td>"
						+"</tr>";
						
					}

				}else{
					shops+="<tr><td colspan=\"4\">没有找到相关店铺</td></tr>";
					}
				  $("#goodsList tr:gt(0)").remove();
				  $("#shopList tr:gt(0)").remove();
			    $("#goodsList").append(goods);
			    $("#shopList").append(shops);
	
		   }
		});

	};
	function initData(){

		$.ajax({
			   type: "POST",
			   url: path+"index/index_initGoodsAndShop.do",
			   data: "",
			   success: function(root){
			    // alert( "Data Saved: " + root );
			     var root=eval('('+root+')');
			     var goodsList=root.goodsList;
			     var shopList=root.shopList;
				var goods="";
				
				for ( var i = 0; i < goodsList.length; i++) {
					goods+="<tr>"
					+"<td><a href='"+goodsList[i].nameUrl+"' target=\"_blank\"><img src=\""+goodsList[i].imgUrl+"\" style=\"width: 200px;height: 100px\"></a></td>"
	        		+"<td ><a href=\""+goodsList[i].nameUrl+"\"  target=\"_blank\">"+goodsList[i].name+"</a></td>"
	        		+"<td>"+goodsList[i].createAuthor+"</td>"
	        		+"<td>"+goodsList[i].createDate+"</td>"
	        		+"<td>"+goodsList[i].goodsType+"</td>" 
	        		+"<td>"+goodsList[i].other+"</td>"
					+"</tr>";
					
				}
				var shops="";
				for ( var i = 0; i < shopList.length; i++) {
					shops+="<tr>"
				   +"<td>"+shopList[i].id+"</td>"
	        		+"<td ><a href=\"shop/shop_shopIndex.do?shop.id="+shopList[i].id+"\"  target=\"_blank\">"+shopList[i].shopName+"</a></td>"
	        		+"<td>"+shopList[i].shopkeeper+"</td>" 
	        		+"<td>"+shopList[i].createDate+"</td>"
					+"</tr>";
					
				}
			     $("#goodsList").append(goods);
			     $("#shopList").append(shops);
			     
			   }
			});

		};
	function login(){
		var username=$("#username").val();
		var password=$("#password").val();
		if(username==""||password==""){
	alert("用户名或密码不能为空！");
	return;
			}
		
		$.ajax({
			   type: "POST",
			   url: path+"user/user_login.do",
			   data:{"user.username":username,"user.password":password},
			   success: function(root){
			     var root=eval('('+root+')');
			 	
			 	if(undefined!=root.error){
			 		var str=$("#login");
			 		str.append(root.error);
			 		
				 	}else{		
				 	
					$("#login").html("欢迎"+root.username+"登陆！      "+"<a href=\""+path+"user/user_entryManger.do\" target=\"_blank\">进入后台管理</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\""+path+"logout\">注销</a>");
					}
			   }
			});


		}
	function checkLogin(){
		$.ajax({
			   type: "POST",
			   url: path+"user/user_checkLogin.do",
			   data:"",
			   success: function(root){
			     var root=eval('('+root+')');
			 	
			 	if(root.isLogin){						 	
					$("#login").html("欢迎"+root.username+"登陆！      "+"<a href=\""+path+"user/user_entryManger.do\" target=\"_blank\">进入后台管理</a>"+"<a href=\""+path+"logout\">注销</a>");
					}
			   }
			});


		}
	var path;
	$(document).ready(function(){
		path=document.getElementById("path").value;
		checkLogin();
		initData();
	});
	
	</script>
	<script type="text/javascript">
	function bookmark() {
		var title = document.title;
		var url = document.location.href;
		if (window.sidebar)
			window.sidebar.addPanel(title, url, "");
		else if (window.opera && window.print) {
			var mbm = document.createElement('a');
			mbm.setAttribute('rel', 'sidebar');
			mbm.setAttribute('href', url);
			mbm.setAttribute('title', title);
			mbm.click();
		} else if( document.all ) window.external.AddFavorite( url, title);
	}
</script>

	<style type="text/css">
td{
text-align: center;
width: auto;
}
body{
background-color: CCFFCC;
}

</style>
  </head>
  
  <body>
  <center>
  <div style="width: 1200px;height: auto;text-align: center;">
  <input type="hidden" id="path" value="${path}">
  <div style="float: left;"><a href="javascript:bookmark()">加入收藏夹</a>
</div>
  <div id="login" style="top:0px;height: 30px;width: 100%;right: 0px;text-align: right;">
 用户名：<input type="text" id="username" name="user.username" style="width: 150px;">
密码：  <input type="password" id="password" name="user.password" style="width: 150px;">
     <input type="button" name="login" value="登陆" onclick="login();">
 	<a href="${path}user/user_addUI.do">注册</a>
  </div> 
   <center>
  <input type="text" name="search" id="search" style="width: 400px;">
  <input type="button" name="goods" id="serch_goods" value="搜索商品" onclick="search(this);">
  <input type="button" name="shop" id="serch_shop" value="搜索店铺" onclick="search(this);">
</center>
<center>
<h2>店铺列表</h2>
        <table width="100%" border="1" id="shopList">
            <tr>
			 <th >店铺ID</th>
			 <th>店铺名称</th>
			 <th>店铺所有者</th>
			 <th>创建时间</th>
            </tr>
        </table>
<h2>商品列表</h2>
       <table width="100%" border="1" id="goodsList">
            <tr>
            	<th>商品图片</th>
            	<th>商品名称</th>
            	<th>商品添加者</th>
            	<th>商品添加时间</th>
            	<th>商品类型</th>
            	<th>备注</th>
            </tr>
        </table>
        
 
 </center>
 </div>
 </center>
  </body>
</html>
